<?php
namespace common\model;
use common\model\common_model;

/**
 * config模型数据库操作类
 */
class config_model extends common_model
{
    public $table_name = 'config';
    public $_pk         = 'id';
    //已删除
    const GROUP_WEBSITE  = 1;
    //关闭
    const GROUP_USER      = 2;

    public function __construct()
    {
        $this->db_config  = load_config('database');
        $this->db_setting = 'default';
        parent::__construct();

    }

    /**
     * 保存配置
     * @param $configs
     * @return bool
     * @throws \Exception
     */
    public function saveConfigs($configs)
    {
        if(is_array($configs)){
            foreach($configs AS $k=>&$v){
                $op = $this->update(['value'=>$v],['key'=>$k]);
                if(!$op){
                    throw new \Exception($this->getError(),-100);
                }
            }
        }
        return true;
    }


    public function getAllConfig()
    {
        $list = $this->select([],'*','','','','key');
        return $list;
    }
}